package com.itheima.api.stream.demo02;

import java.util.ArrayList;
import java.util.stream.Stream;

public class StreamDemo01 {

    public static void main(String[] args) {

        ArrayList<Integer> arrayList1 = new ArrayList<Integer>();

        arrayList1.add(23);
        arrayList1.add(12);
        arrayList1.add(56);
        arrayList1.add(34);
        arrayList1.add(89);
        arrayList1.add(45);

        arrayList1.stream().filter(s -> s > 30).forEach(s -> System.out.println(s));

        System.out.println("----------------------------------------------------");

        arrayList1.stream().limit(3).forEach(s -> System.out.println(s));

        System.out.println("----------------------------------------------------");

        arrayList1.stream().skip(3).forEach(s -> System.out.println(s));

        System.out.println("----------------------------------------------------");

        ArrayList<Integer> arrayList2 = new ArrayList<Integer>();
        arrayList2.add(34);
        arrayList2.add(100);
        arrayList2.add(12);

        Stream<Integer> stream1 = arrayList1.stream();

        Stream<Integer> stream2 = arrayList2.stream();

        Stream<Integer> stream = Stream.concat(stream1, stream2);
//        stream.forEach(s -> System.out.println(s));

        System.out.println("------------------------------------------------------------------");

        //去重
//        stream.distinct().forEach(s -> System.out.println(s));

        System.out.println("------------------------------------------------------------------");

        //自然排序
//        stream.distinct().sorted().forEach(s -> System.out.println(s));

        System.out.println("------------------------------------------------------------------");

        stream.distinct().sorted((s1, s2) -> s2 - s1).forEach(s -> System.out.println(s));

    }

}
